//
//  TwoViewController.m
//  RAC的简单应用
//
//  Created by wsj on 16/8/14.
//  Copyright © 2016年 wsj. All rights reserved.
//

#import "TwoViewController.h"
#import "NetworkViewModel.h"
/*屏幕的宽度*/
#define kWJScreenWidth [UIScreen mainScreen].bounds.size.width
/*屏幕的高度*/
#define kWJScreenHeight  [UIScreen mainScreen].bounds.size.height
@interface TwoViewController ()
/**创建网络请求的VM*/
@property(nonatomic,strong)NetworkViewModel *networkModel;
/**<#创建的界面tableView#>*/
@property(nonatomic,strong)UITableView *tableView;


@end

@implementation TwoViewController
-(NetworkViewModel *)networkModel
{
    if (_networkModel == nil) {
        _networkModel = [[NetworkViewModel alloc]init];
    }
    return _networkModel;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor redColor];
    
    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 200, 100)];
    [button setTitle:@"消失吧，改变别人的背景去吧" forState:0];
    __weak typeof(self) weakShef = self;
    [[button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
        // 判断信号时有有值
        if (weakShef.backgroundColor_signal) {
            // 发送信号
            [weakShef.backgroundColor_signal sendNext:[UIColor redColor]];
        }
        [weakShef dismissViewControllerAnimated:YES completion:nil];
    }];
    [self.view addSubview:button];
    
    /**创建tableView*/
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 100,kWJScreenWidth , kWJScreenHeight-100)];
    tableView.dataSource = self.networkModel;
    [self.view addSubview:tableView];
    self.networkModel.tableView = tableView;
    
    // 执行信号 也就是开启网络请求
    [self.networkModel.command execute:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)dealloc
{
    NSLog(@"%s",__FUNCTION__);
}

@end
